package com.wyy.mall.tiny.controller;

import com.wyy.mall.tiny.common.api.CommonResult;
import com.wyy.mall.tiny.nosql.mongodb.document.MemberReadHistory;
import com.wyy.mall.tiny.service.MemberReadHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员商品浏览记录管理Controller
 * created by 伍猷煜 on 2021/5/20 21:39 星期四
 */
@Api(tags = "MemberReadHistoryController", description = "会员商品浏览记录管理")
@Controller
@RequestMapping("/member/readHistory")
public class MemberReadHistoryController {

    @Autowired
    private MemberReadHistoryService mMemberReadHistoryService;

    @ApiOperation("创建浏览记录")
    @PostMapping("/create")
    @ResponseBody
    public CommonResult create(@RequestBody MemberReadHistory memberReadHistory) {
        int count = mMemberReadHistoryService.create(memberReadHistory);
        if (count > 0) return CommonResult.success(count);
        else return CommonResult.failed();
    }

    @ApiOperation("删除浏览记录")
    @PostMapping("/delete")
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<String> ids) {
        int count = mMemberReadHistoryService.delete(ids);
        if (count > 0) return CommonResult.success(count);
        else return CommonResult.failed("删除浏览记录失败！");
    }

    @ApiOperation("展示浏览记录")
    @GetMapping("/list")
    @ResponseBody
    public CommonResult<List<MemberReadHistory>> list(Long memberId) {
        List<MemberReadHistory> memberReadHistories = mMemberReadHistoryService.list(memberId);
        return CommonResult.success(memberReadHistories);
    }
}
